

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;


public class CustomBroker extends DatacenterBroker {
public static ArrayList<CustomCloudlet> cloudletList;
	public CustomBroker(String name) throws Exception {
		super(name);
		// TODO Auto-generated constructor stub
	}
	public static void main(String[]args)
	{
		createCloudletList("Assignment/workload/workload.txt");
		for(CustomCloudlet d:cloudletList)
		{
			System.out.println(d.getSubmissionTime()+","+d.getDeadline());
		}
	}
	public static void createCloudletList(String filename)
	{
		BufferedReader br = null;
		cloudletList=new ArrayList<CustomCloudlet>();
		 List<Cloudlet>cloudletList=new ArrayList<Cloudlet>();
		try {
 
			String sCurrentLine;
 
			br = new BufferedReader(new FileReader(filename));
			int cloudletId=0;
			while ((sCurrentLine = br.readLine()) != null) {
				//cloudlet properties will keeped in attribute
				String attribute[]=sCurrentLine.split(" ");
				long submissTime= new Long(attribute[0]);
				long cloudletLength=new Long(attribute[1]);
				long minimumMemory=new Long(attribute[2]);
				long minimumStorage=new Long(attribute[3]);
				long deadline=new Long(attribute[4]);
				int pesNumber=0;
				int cloudletFileSize=300;
				int cloudletOutputSize=300;
				UtilizationModel utilizationModel = new UtilizationModelFull();
				CustomCloudlet cusCloudlet=new CustomCloudlet(cloudletId, cloudletLength, pesNumber, cloudletFileSize, cloudletOutputSize, utilizationModel, utilizationModel, utilizationModel, minimumMemory, minimumStorage,deadline);
				cusCloudlet.setSubmissionTime(submissTime);
				
				CustomBroker.cloudletList.add(cusCloudlet);
				cloudletId++;
				
			}
 
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null)br.close();
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}
	}

}
